package com.yidianyanglao.core.util;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/11/17.
 */
public class SendMsg {

    /**
     * 阿里云短信通道
     * @param vcode
     * @param mobile
     */
    public static void sendMsg(String vcode,String mobile){
        String code = "{\"CODE\":\""+vcode+"\"}";

        String host = "http://sms.market.alicloudapi.com";
        String path = "/singleSendSms";
        String method = "GET";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE 64c71f44007b4f949d83649df81fe4a5");
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("ParamString", code);
        querys.put("RecNum", mobile);
        querys.put("SignName", "一点养老");
        querys.put("TemplateCode", "SMS_26200216");

        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //System.out.println(response.getEntity());
            System.out.println("aliyun:"+EntityUtils.toString(response.getEntity()));
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    public static void main(String[] args){
        String code = "{\"CODE\":\""+123456+"\"}";

        String host = "http://sms.market.alicloudapi.com";
        String path = "/singleSendSms";
        String method = "GET";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE 64c71f44007b4f949d83649df81fe4a5");
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("ParamString", code);
        querys.put("RecNum", "18357116932");
        querys.put("SignName", "一点养老");
        querys.put("TemplateCode", "SMS_26200216");

        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //System.out.println(response.getEntity());
            System.out.println("结果查看："+EntityUtils.toString(response.getEntity()));
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
